﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using MyMeetup.Entities;

namespace MyMeetup.ViewModels
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class RateItViewModel : ViewModelBase
    {
        private DataService _dataService;
        public RelayCommand SubmitRatingCommand { get; private set; }
        /// <summary>
        /// Initializes a new instance of the RateItViewModel class.
        /// </summary>
        public RateItViewModel()
        {
            _dataService = new DataService();
            SubmitRatingCommand = new RelayCommand(SubmitRating);
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real": Connect to service, etc...
            ////}
        }

        public string ApplicationTitle
        {
            get { return "my meetup"; }
        }

        public string PageName { get; set; }

        public string EventId { get; set; }


        private void SubmitRating()
        {
            var rating = new EventReview {event_id = EventId, rating = MyRating, review = MyRatingComments};
            _dataService.PostEventRating(rating, callback, ResponseHelper.ErrorCallback);
        }

        private void callback(EventReview eventRating)
        {
            var e = eventRating;
        }


        /// <summary>
        /// The <see cref="MyRating" /> property's name.
        /// </summary>
        public const string MyRatingPropertyName = "MyRating";

        private int _myrating;

        /// <summary>
        /// Gets the MyRating property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public int MyRating
        {
            get
            {
                return _myrating;
            }

            set
            {
                if (_myrating == value)
                {
                    return;
                }

                _myrating = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(MyRatingPropertyName);
            }
        }


        /// <summary>
        /// The <see cref="MyRatingComments" /> property's name.
        /// </summary>
        public const string MyRatingCommentsPropertyName = "MyRatingComments";

        private string _myRatingComments = "";

        /// <summary>
        /// Gets the MyRatingComments property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public string MyRatingComments
        {
            get
            {
                return _myRatingComments;
            }

            set
            {
                if (_myRatingComments == value)
                {
                    return;
                }

                _myRatingComments = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(MyRatingCommentsPropertyName);

            }
        }

    }
}